package reflect;

import java.lang.reflect.Field;

public class ReflectDemo8 {
    public static void main(String[] args) throws Exception {
        Teacher teacher = new Teacher();
        teacher.name = "李四";
        System.out.println(teacher.name);

        Class cls = Class.forName("reflect.Teacher");
        Object obj = cls.newInstance();
        /*
            Field也是反射对象之一
            它的每一个实例用于表示类中的某个属性
         */
        Field field = cls.getField("name"); //获取Teacher类中的name属性
        field.set(obj, "张三");//obj.name = "张三";
        //System.out.println(obj.name);
        System.out.println(field.get(obj));
    }
}
